在我的情况下,hover() 事件没有触发



http://jsfiddle.net/FT4CQ/

$(document).ready(function(){
  $('.cell').hover(function(){
    $('this').css('background-size','cover');
  });
});

我错过了什么吗?我想悬停以缩小并使用 css 全面预览图片。

这很好用:

$(document).ready(function(){
  $('.cell').hover(function(){
    $(this).css('background-size','cover');
  });
});

删除 $('this') 中的单引号。 现在要更改$(这个),它工作得很好.

这是工作代码。 你没有包括Jquery。

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $('.cell').hover(function(){
    alert('hover work');
  });
});
</script>
    <div class="cell" style="width: 345.53px; height: 210.53px; 
    background-image: 
     url(https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-prn1/1521894_10151755196011682_1359230168_n.jpg);  
   position: absolute;-webkit-transition: top 0.5s, left 0.5s; 
   transition: top 0.5s, left 0.5s;" data-delay="2" 
   data-height="200" data-width="331" data-state="move" id="2-2"></div>

工作解决方案:http://jsfiddle.net/FT4CQ/23/

如前所述,您不应该在$(this)中使用单个引号。另外,在示例中,我添加了一个鼠标退出功能,以重置background-size

你忘了在你的小提琴中加入jQuery

您的代码工作正常。

$(document).ready(function(){
  $('.cell').hover(function(){
    $('this').css('background-size','cover');
  });
});

在这里工作小提琴。

相关内容

最新更新