Jquery悬停输入输出问题
为什么这不起作用? 说明:我有一个容器(带有.hover的div)。悬停时,.thumbtxt2应该从左侧滑入,它确实滑入,但仅在第一次滑入时。然后,它从右边滑入Jquery悬停输入输出问题,jquery,Jquery,为什么这不起作用? 说明:我有一个容器(带有.hover的div)。悬停时,.thumbtxt2应该从左侧滑入,它确实滑入,但仅在第一次滑入时。然后,它从右边滑入 var $j = jQuery.noConflict(); $j(document).ready(function () { $j(".hover").hover(function () { $j(this).find('.thumbtxt2').css("left", "-220"); if
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j(".hover").hover(function () {
$j(this).find('.thumbtxt2').css("left", "-220");
if ($j(window).width() > 1050) {
$j(this).find('.thumbimg').stop().animate({
opacity: .0
}, 200);
$j(this).find('.thumbtxt2').stop().animate({
left: 0
}, 200);
} else {
$j(this).find('.thumbimg').stop().animate({
opacity: .5
}, 200);
};
},
function () {
if ($j(window).width() > 1050) {
$j(this).find('.thumbimg').stop().animate({
opacity: 1
}, 200);
$j(this).find('.thumbtxt2').stop().animate({
left: 220
}, 200, function () {
$j(this).find('.thumbtxt2').css("left", "-220");
});
} else {
$j(this).find('.thumbimg').stop().animate({
opacity: 1
}, 200);
};
});
});
谢谢 对于匹配选择器的可能动态元素,请使用的版本。比如:
jQuery.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
$(document).on('mouseenter', '.hover', function(e) {
var t = $(this).find('.thumbimg'),
t2 = $(this).find('.thumbtxt2').css('left', -220);
if ($(window).width() < 9999) {
t.stop().animate({ opacity: .0 }, 200);
t2.stop().animate({ left: 0 }, 200);
}
else {
t.stop().animate({ opacity: .5 }, 200);
};
})
.on('mouseleave', '.hover', function(e) {
var t = $(this).find('.thumbimg'),
t2 = $(this).find('.thumbtxt2');
if ($(window).width() < 9999) {
t.stop().animate({ opacity: 1 }, 200);
t2.stop().animate({ left: 220 }, 200);
}
else {
t.stop().animate({ opacity: 1 }, 200);
};
})
});
// Code that uses other library's $ can follow here.
jQuery.noConflict();
jQuery(文档).ready(函数($){
//使用jQuery的$的代码如下所示。
$(文档).on('mouseenter','.hover',函数(e){
var t=$(this.find('.thumbimg'),
t2=$(this.find('.thumbtxt2').css('left',-220);
如果($(窗口).width()<9999){
t、 停止().animate({opacity:.0},200);
t2.stop().animate({left:0},200);
}
否则{
t、 停止()。设置动画({opacity:.5},200);
};
})
.on('mouseleave','.hover',函数(e){
var t=$(this.find('.thumbimg'),
t2=$(this.find('.thumbtxt2');
如果($(窗口).width()<9999){
t、 停止()。设置动画({opacity:1},200);
t2.stop().animate({left:220},200);
}
否则{
t、 停止()。设置动画({opacity:1},200);
};
})
});
//使用其他库的$的代码可以在这里找到。
出于某种原因,
t2=$(this.find('.thumbtxt2').css(“left”,“-220”)代码>不起作用。
使用.animate()t2=$(this).find('.thumbtxt2').animate({left:-220},0)代码>工作。
此时不需要mouseout上的完整功能
这是小提琴:
什么版本的jQuery?您可以添加一个JSFIDLE来说明问题吗?您应该存储对象,而不是重复搜索(.find)对象。忘记JSFIDLE:感谢您优化代码。但它还没有达到我想要的效果。这里有一个问题:问题出在哪里。这正是你想要的。这就是我最初问题的答案。