douzhu1188 2011-11-29 16:54
浏览 32
已采纳

jQuery刷新停止jQuery悬停工作

I'm using the script below to refresh a div when the text 'view more' is clicked. The div loads a bunch of random images from the rotate.php file. For some reason though, the jquery hover effects that I have applied no longer work after the div has been refreshed. I did try adding the jquery hover script to the rotate.php file, but that stops the refresh script from working... :S Does anyone have any ideas on how you could fix this? :)

<div class="headingtext">
<script type='text/javascript'>
$(function() {
  $("#refresh").click(function(evt) {
     $(".feature").load("rotate.php")
     evt.preventDefault();
  })
})
</script><a id="refresh" href="#">View More</a>
        </div>

        <div class="feature">
            <?php include('rotate.php') ?>
        </div>

The jquery I have applied to the images, but stops working after refresh:

 $(document).ready(function(){
 $(".feature img").hover(function() {
  $(this).stop().animate({opacity: "0.5"}, 'slow');
},
function() {
  $(this).stop().animate({opacity: "1"}, 'slow');
});
});

The PHP (rotate.php):

<?php 
$random = "random.txt";
$fp = file($random);
shuffle($fp);
$keys = array_rand($fp, 3);
for ($i = 0; $i < 3; $i++):
$rl = $fp[$keys[$i]]; 
echo $rl;
endfor;
?>
  • 写回答

2条回答 默认 最新

  • doulun7739 2011-11-29 16:57
    关注

    You must use the on function ( http://api.jquery.com/on/ )

    replace :

     $(".feature img").hover(function() {
    

    by

    $(".feature img").on("mouseover", function() {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊