Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

385
Visualizações
when using ajax to load a view component the view components javaScript Codes doesn't work

i used a view Component that has some javaScript codes for animations. when page loaded javaScript works well but when click a button to load data with ajax, data loaded correctly but javaScript codes doesn't work any more

// in view component code

   public async Task<IViewComponentResult> InvokeAsync(GalleryInvokeParameterViewModel par)
    {
    var gallery = await _productService.GetGalleriesForSingleProductAsync(par.ProductID,par.ColorID);
    ViewBag.mainImage = await _productService.GetMainImageGalleryForSingleProductAsync(par.ProductID, par.ColorID);
    ViewBag.productId = par.ProductID;
    return View("SingleProductGallery",gallery);
    }

// in controller

    public IActionResult ChangeGallery(int id, int colorId)
{
var parameters = new GalleryInvokeParameterViewModel
{
ColorID = colorId,
ProductID = id
};
return ViewComponent("SingleProductGallery", parameters);
}

// in javascript codes for ZOOM image ON HOVER IMAGE // these codes doesn't work after calling ajax to load data

    var zoomArea = document.getElementById("zoom-area");
var zoomImage = document.getElementById("zoom-image");
zoomArea.addEventListener("mousemove", function (event) {
var clientX = event.clientX - zoomArea.offsetLeft;
var clientY = event.clientY - zoomArea.offsetTop;
var aWidth = zoomArea.offsetWidth;
var aHeight = zoomArea.offsetHeight;
clientX = (clientX / aWidth) * 100;
clientY = (clientY / aHeight) * 100;
zoomImage.style.transform =
"translate(-" + clientX + "% , -" + clientY + "%) scale(1.5)";
});
$(zoomArea).mouseleave(function () {
zoomImage.style.transform = "translate(-50% , -50%) scale(1)";
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i found a solution for this issue. after ajax called and returned data i call :

        $(document).ajaxComplete(function () {js code});

and it reloaded javaScript codes again and my animations code works well.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda