[英]Can't get fade out function to work more than once
So this is the code that I have written. 这就是我编写的代码。 i have very little knowledge of jquery and just tried to write what I saw. 我对jquery的了解很少,只是想写我所看到的。 I am sure their is an easier I run it once and it will work but after that it just stays the some for each click and does not call the function back up for the next click. 我确信他们可以更轻松地运行一次,并且可以运行,但是此后每次单击都会保留一些,并且不会在下次单击时调用该函数。 I am having the same problem on another script that I have, I can't seem to call a function more than one time. 我在另一个脚本上遇到了同样的问题,我似乎不能多次调用一个函数。 One and done it what it seems to do. 一并完成它似乎要做的事情。 Any help would be much appreciated. 任何帮助将非常感激。
$.noConflict();
jQuery(document).ready(function ($) {
$("#scrollmenu");
$("#e_emd").click(function () {
$("#e_em").show();
$("#e_v").delay(1200).fadeOut("slow");
$("#e_s").delay(1200).fadeOut("slow");
$("#e_l").delay(1200).fadeOut("slow");
});
$("#e_vd").click(function () {
$("#e_em").delay(1200).fadeOut("slow");
$("#e_v").show();
$("#e_s").delay(1200).fadeOut("slow");
$("#e_l").delay(1200).fadeOut("slow");
});
$("#e_sd").click(function () {
$("#e_em").delay(1200).fadeOut("slow");
$("#e_v").delay(1200).fadeOut("slow");
$("#e_s").show();
$("#e_l").delay(1200).fadeOut("slow");
});
$("#e_ld").click(function () {
$("#e_em").delay(1200).fadeOut("slow");
$("#e_v").delay(1200).fadeOut("slow");
$("#e_s").delay(1200).fadeOut("slow");
$("#e_l").show();
});
});
<!-- THIS IS USED MULTIPLE TIMES IN THE PAGE BEING USED ON FOR SCROLLING CONTENT -->
<div id="scrollmenu">|
<a id="e_emd" href="#Event_Management" class="panel">Event Management</a> |
<a id="e_vd" href="#Video" class="panel">Video</a> |
<a id="e_sd" href="#Sound" class="panel"></a>Sound |
<a id="e_ld" href="#Lighting" class="panel">Lighting & Staging</a> |
</div>
<img id="e_em" src="images/eventmanage.png" width="1037" height="480" />
<img id="e_v" src="images/video.png" width="1128" height="480" />
<img id="e_s" src="images/sound.png" width="1011" height="480" />
<img id="e_l" src="images/light.png" width="1011" height="480" />
I have upoloaded the full page I am working on. 我已经上传了我正在处理的整个页面。
The site I am trying it on is here http://www.mac-av.com/test2/ 我正在尝试的网站在这里http://www.mac-av.com/test2/
What I am seeing is that I can't use an id more than once to call a function where i have 我看到的是,我不能多次使用id来调用我拥有的函数
<div id="scrollmenu">|
<a id="e_emd" href="#Event_Management" class="panel">Event Management</a> |
<a id="e_vd" href="#Video" class="panel">Video</a> |
<a id="e_sd" href="#Sound" class="panel"></a>Sound |
<a id="e_ld" href="#Lighting" class="panel">Lighting & Staging</a> |
</div>
Multiple times on the same page 在同一页面上多次
I am needing each image to change differently for every button that is clicked for ever category because of the scrolling that I have. 由于需要滚动,因此我需要为每一个被点击的按钮的每个类别的图像进行不同的更改,以便永远点击。 I am doing this because when the page it on a computer with a low resolution the image will appear on the left side under the content window of the next category. 我这样做是因为,当在低分辨率的计算机上对其进行分页时,图像将出现在下一类别内容窗口的左侧。 So making this script was suppose to hide the images from it and only show the ones that are there for the category it is on, but also be able to see the other as it scrolls before they disappear. 因此,假设制作此脚本是要隐藏其中的图像,并且仅显示其所在类别的图像,而且还可以在滚动时看到其他图像,然后消失。
It will work for the first set of buttons, but not afterwards. 它适用于第一组按钮,但不适用于随后的按钮。 I am realizing that I can only call them once with the id, but instead of making a different script for each one, is there an easier way? 我意识到我只能用id调用一次,但是没有为每个脚本创建不同的脚本,有没有更简单的方法?
Why are you using the $.noConflict(); 为什么要使用$ .noConflict(); ? ? Try removing that. 尝试删除它。 Also try removing the $ from your ready function and using it instead of "jQuery", so it looks as follows: 另外,请尝试从就绪函数中删除$并使用它代替“ jQuery”,这样它看起来如下:
$(document).ready(function () {
// blah blah
});
And yes, document.ready fires when it's loaded, but you are linking your ids to events, so they should be fine. 是的,document.ready在加载时会触发,但是您将id链接到事件,因此它们应该没问题。 Do you have any 3rd party controls or other ajax controls on this page? 您在此页面上是否有任何第三方控件或其他ajax控件?
Could you put up a link to the page? 您能否在页面上放置一个链接? If you could do this, I could debug it quickly. 如果可以这样做,我可以快速对其进行调试。 fadeOut
will work more than once, so there must be something up with your on-page script and selectors. fadeOut
将不止一次地工作,因此页面脚本和选择器必须有一些功能。
Tips that might help in the meantime: 在此期间可能有帮助的提示:
$("#scrollmenu");
您有一个随机的$("#scrollmenu");
declaration at the top that isn't doing anything... you can get rid of that 顶部没有做任何事情的声明...您可以摆脱它 A few things: 一些东西:
id
s can only be used once per page 每个页面只能使用id
一次 jQuery can read element attributes, so take advantage of it. jQuery可以读取元素属性,因此可以利用它。
<script type="text/javascript">
$(document).ready(function(){
// when any link inside scrollmenu is clicked
$(".scrollmenu a").click(function (e) {
// don't follow the link
e.preventDefault();
// find out which image to show
var target_id = $(this).attr('href');
// fadeOut all visible images inside .images that isn't the one we'll show
$('.images img').is(':visible').not(target_id).fadeOut("slow");
// show the target
$(target_id).show();
});
});
</script>
<div class="scrollmenu">|
<a href="#e_em">Event Management</a> |
<a href="#e_v">Video</a> |
<a href="#e_s"></a>Sound |
<a href="#e_l">Lighting & Staging</a> |
</div>
<div class="images">
<img id="e_em" src="images/eventmanage.png" width="1037" height="480" />
<img id="e_v" src="images/video.png" width="1128" height="480" />
<img id="e_s" src="images/sound.png" width="1011" height="480" />
<img id="e_l" src="images/light.png" width="1011" height="480" />
</div>
You could combine this with @JonH's method for more complicated sequences of animations. 您可以将其与@JonH的方法结合使用,以获得更复杂的动画序列。
I set up an example for you to further elaborate on my comment. 我为您提供了一个示例,以进一步阐述我的评论。 http://jsfiddle.net/jMQhZ/11/ http://jsfiddle.net/jMQhZ/11/
Clicking the first box will fire the #e_emd
click event. 单击第一个框将触发#e_emd
点击事件。 If you click that again, nothing will happen because the function has nothing to do. 如果再次单击该按钮,则不会发生任何事情,因为该功能无关。 If you click show all you'll see that all the divs
are set back to normal. 如果单击全部显示,您将看到所有divs
均恢复为正常。 Now clicking the #e_emd
div will run your function again. 现在单击#e_emd
div将再次运行您的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.