Jquery:仅移动右侧容器

发布于 2024-10-06 12:59:29 字数 575 浏览 1 评论 0原文

我已经为图片列表完成了以下代码,当用户将鼠标悬停在图片上时,会显示 alt:

我想知道是否有任何我可以仅移动鼠标悬停的元素,而不是像我一样移动所有元素现在。

#{list items:gallery.listPictures(), as:'picture'}
    <a class="pic" href="@{Galleries.showPicture(picture.id)}"><img src="@{Application.getPicture(picture.id)}" alt="${picture.name}" />
        <span class="alt">${picture.name}</span>
    </a>
#{/list}
<script type="text/javascript">
$(function(){
$(".pic").mouseover(function(event){
    $(".alt").css({'top': event.pageY, 'left': event.pageX});  
});

});

I have done the following code for a list of pics, when the user mouseover the picture an alt is showing up:

I would like to know if there is anyway I can move the mouseover'ed element only and not all of them like i do now.

#{list items:gallery.listPictures(), as:'picture'}
    <a class="pic" href="@{Galleries.showPicture(picture.id)}"><img src="@{Application.getPicture(picture.id)}" alt="${picture.name}" />
        <span class="alt">${picture.name}</span>
    </a>
#{/list}
<script type="text/javascript">
$(function(){
$(".pic").mouseover(function(event){
    $(".alt").css({'top': event.pageY, 'left': event.pageX});  
});

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不爱素颜 2024-10-13 12:59:29
<script type="text/javascript">
$(function(){
$(".pic").mouseover(function(event){
    $(this).find(' > span').css({'top': event.pageY, 'left': event.pageX});  
});
</script>

注意$(this)。在 jQuery 函数中 this 将访问触发事件的当前元素。

请参阅 jQuery 选择器jQuery 子选择器jQuery .find()

<script type="text/javascript">
$(function(){
$(".pic").mouseover(function(event){
    $(this).find(' > span').css({'top': event.pageY, 'left': event.pageX});  
});
</script>

Notice the $(this). Inside a jQuery function this will access the current element that fired the event.

See jQuery selectors and jQuery child-selector and jQuery .find()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文