简体   繁体   English

jQuery 图片点击隐藏/显示

[英]jQuery image click hide/show

i have googled much about this problem but sadly havent found a working solution and i dont have any expertise in javascript sadly.我在谷歌上搜索了很多关于这个问题的信息,但遗憾的是还没有找到可行的解决方案,遗憾的是我在 javascript 方面没有任何专业知识。

I want to achieve the following:我想实现以下目标:

  1. Having a sticky bar at the bottom of the website (done) which automatically closes after 5 seconds after opening the page (not done)在网站底部有一个粘性栏(完成),在打开页面 5 秒后自动关闭(未完成)
  2. After 5 seconds the sticky bar should automatically slide down and only an orange arrow (which is an image) should be visible 5 秒后,粘性条应自动向下滑动,并且应该只看到一个橙色箭头(这是一个图像)

I managed to implement a jquery script which already achieves the content "closing" when i click on the button.我设法实现了一个 jquery 脚本,当我单击按钮时,它已经实现了内容“关闭”。

But i cant manage to link the image to do the same functionality as the button and i dont know what to do.但我无法设法链接图像以执行与按钮相同的功能,我不知道该怎么做。

Plus the automatic 5 seconds closing after opening the page is also not implemented yet.加上打开页面后自动关闭 5 秒也没有实现。

The jquery script: jquery 脚本:

 jQuery(document).ready(function(){ jQuery('#hideshow').on('click', function(event) { jQuery('#content').toggle('show'); }); });

Here is the working button at the top which hides "Hello World" and at the bottom there is the orange image with the white arrow which sould have the same functionality as the button above to hide the content directly under it.这是顶部的工作按钮,它隐藏了“Hello World”,底部是带有白色箭头的橙色图像,它与上面的按钮具有相同的功能,可以直接隐藏其下方的内容。

Code from the "Hello World" and Button来自“Hello World”和按钮的代码

Code from the orange image with the white arrow带有白色箭头的橙色图像中的代码

Code from the content with orange background under the image with the arrow带有箭头的图像下方带有橙色背景的内容中的代码

Use setTimeout() method, you can learn more about it here So you could do this:使用 setTimeout() 方法,你可以在这里了解更多所以你可以这样做:

jQuery(document).ready(function(){
    setTimeout(function(){
        jQuery('#content').addClass('hide'); // or toggle using 'show' class
    }, 5000);

    jQuery('#hideshow').on('click', function(event) {        
        jQuery('#content').toggle('show');
    });
});

In code with arrow button use tag, like:在带有箭头按钮的代码中使用标签,例如:

<div class="bar">
    <a href="#" id="closeButton" class="arrowBtn"><img src="arrow.png" alt="Arrow button"></a>
</div>

Then you could use jQuery to listen on click event on that button:然后你可以使用 jQuery 来监听该按钮上的点击事件:

jQuery('#closeButton').on('click', function(event) {
    event.preventDefault();
    $('#content').toggle('show');
});

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

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