简体   繁体   English

Javascript-在悬停时加载div和内容

[英]Javascript - Load div and content on hover

I got a little problem. 我有一个小问题。 I have to load content in a div, when the user hover over a div. 当用户将鼠标悬停在div上时,我必须在div中加载内容。

<div id="table">
<div class="hoverover">
    <!--<img src="ImageLink">-->
    Image goes here.
</div>
</div>

The div "table" is where the users mouse have to be to show the second div. 用户必须在div“表”中显示第二个div。 The div "hoverover" must only be loaded if the users mouse is in the div "table". 仅当用户鼠标在div“表”中时才可以加载div“悬停”。 So any pictures in the div "hoverover" is not loaded before the users mouse is in "table". 因此,在用户鼠标位于“表格”中之前,不会加载div“悬停”中的任何图片。

I have been looking at this, but it's not what I was searing for. 我一直在看这个,但这不是我想要的。 jsfiddle.net/LD8t6/ and this http://jsfiddle.net/ujBZY/9/ (Am I stupid or.. since I can not get this to work?) jsfiddle.net/LD8t6/和此http://jsfiddle.net/ujBZY/9/ (我是愚蠢还是..因为我无法使它正常工作?)

I have made a fiddle of my progress here: http://jsfiddle.net/Zwipper/xCmxj/ 我在这里取得了进展的小提琴: http : //jsfiddle.net/Zwipper/xCmxj/

If I have overlooked a thread on this topic, I am sorry. 如果我忽略了与此主题相关的话题,很抱歉。 I may have seen me blind to this in my search. 我可能在搜索中发现我对此视而不见。

I have a little problem to get a javascript to load the div "hoverover" properly. 我有一个小问题,要获取一个JavaScript才能正确加载div“ hoverover”。 Can any of you get a javascript to work? 你们任何人都可以使用JavaScript吗? It will be a great help :) 这将是一个很大的帮助:)

I hope this is enough info, this is my first fiddle. 我希望这是足够的信息,这是我的第一个小提琴。 If not, please write :) 如果没有,请写:)

Thanks :) 谢谢 :)

Try this: DEMO HERE 试试这个: DEMO HERE

$('#table').hover(
    function(){$('div.hoverover').show('slow'); },

    function(){$('div.hoverover').hide('slow');}
);

I have found a solution with some ajax. 我找到了一些ajax的解决方案。 This is what I have found: 这是我发现的:

  <a href="#" class="ajaxtrigger">Load Ajax</a>
    <div id="target"></div>

<script src="http://code.jquery.com/jquery-latest.pack.js"></script>

<script>
    $(function(){
   $(".ajaxtrigger").click(function(){

      $("#target").load("load.php #toggle3");   
   });
})
</script>

This is the load.php: 这是load.php:

<?
echo '<div id="#toggle">Toggle 1</div>';
echo '<div id="#toggle2">Toggle 2</div>';
echo '<div id="#toggle3">Toggle 3</div>';
echo '<div id="#toggle4">Toggle 4</div>';
?>

This works when I have the files on me laptop and xampp :) 当我在笔记本电脑和xampp上保存文件时,此方法有效:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM