我正在使用 jquery 制作幻灯片 cycle plugin对于过渡。 现在一切正常,直到我向图像添加超链接。如果用户希望添加超链接,我会尝试添加超链接,所以我的控制台中为每个图像都有一个设置按钮。如果用户选择超链接并单击设置,它应该设置。现在超链接设置正确,但是,然后将转换应用于 anchor 标签而不是 img 标签。 当我设置链接时,img 标签像这样包裹在 anchor 标签内。
<a href="www.google.com" id="link" class="link">
<img id="imgBoxRot_1_1" style="width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; display: none; z-index: 3; opacity: 0;" src="http://localhost/images/layout/slideShow/gallImg1.jpg">
</a>
我像这样动态地创建这个 anchor 标签,并将它附加到图像上。
var newA = document.createElement("a");
newA.setAttribute("id","lnkImgRotImg_"+iCount+"_"+idT);
newA.setAttribute("href",document.getElementById(lnk).value);
newA.setAttribute("class","aTransLink");
newA.setAttribute("target","_blank");
在设置 anchor 标签之前,插件工作正常并应用了过渡,但是在向图像添加 anchor 之后,过渡应用于 anchor 标签而不是图像。我该如何解决这个问题?
感谢抽空。
最佳答案
在研究了插件文档后我了解到,该插件默认应用于 第一个标签,该标签位于其所应用的 div 内。
也就是说,如果我们有
<div class="">
<img></img>
<img></img>
</div>
现在,如果我像这样在图像周围包裹一个 anchor ,
<div class="">
<a href="">
<img></img>
</a>
<img></img>
</div>
该插件混淆了图像标签和 anchor 标签,并将转换应用到 anchor 而不是图像标签(因为它是应用循环插件的 div 之后的第一个).因此,我最初将所有图像都包装在一个 anchor 标记中(之前我动态添加 anchor )并将插件应用于 anchor 本身而不是图像标记。
关于php - 使用 jquery cycle plugin for transitions 动态添加超链接到图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12668870/