简体   繁体   English

关闭JavaScript功能

[英]Turning off a javascript function

I'm building a website which has tooltips to give advice on what to do which display after a few seconds of inactivity. 我正在建立一个网站,该网站具有工具提示,可为在闲置几秒钟后显示的内容提供建议。 The thing is, there's certain circumstances when I don't want them to show up. 问题是,在某些情况下我不希望它们出现。

The website has 'pop-ups' (just div tags on which the z-index is changed). 该网站具有“弹出式窗口”(只是div标签,其上的Z索引已更改)。 When these tags are 'in view' I don't want the tool tips. 当这些标签处于“可见”状态时,我不需要工具提示。 Is there anything I can do to the code to check if a div is at a certain level, or perhaps insert a command to NOT run the tooltip code... 我有什么办法对代码进行检查以检查div是否处于某个级别,或者插入命令以不运行工具提示代码...

My tooltip script is 我的工具提示脚本是

<!-- JavaScript function to show/hide prompts after innactivity-->
<script type="text/javascript">
  $(document).ready(function(){ 
  var interval = 1;
setInterval(function(){
   if(interval == 9){
       $("div.container_prompts_timeout").show(); 
       interval = 1; 
   }
   interval = interval+1;
    console.log(interval);
},1000);

$(document).bind('mousemove keypress', function() {
    $("div.container_prompts_timeout").hide();
    interval = 1; 
});
 });
</script>

And the code I use to change z-index is: 我用来更改z-index的代码是:

<!--Code to change z-index of background divs-->
<script type="text/javascript">
function changeZIndex(i,id) {
  document.getElementById(id).style.zIndex=i;
}
</script>

Many thanks 非常感谢

Why not to use display property of your divs to hide and show them. 为什么不使用div的display属性来隐藏和显示它们。 And you can check the state of it. 您可以检查它的状态。 Something like 就像是

var my_div = getElementById("my_div");// or use your jQuery if you wish

function show() {
    my_div.style.display = "block";
}

function hide() {
    my_div.style.display = "none";
}

function is_shown() {
    if (my_div.style.display == "none") return 0;
    return 1; // use booleans if you wish, I prefer old school :)
}

you could: 你可以:

  • check if the popups are "visible" before showing the tooltips, or 在显示工具提示之前检查弹出窗口是否“可见”,或
  • cancel the interval when they become visible and restart it when they are hidden 当它们变得可见时取消间隔,在它们隐藏时重新启动间隔

personally, I wouldn't use the z-index to show or hide things. 就个人而言,我不会使用z-index来显示或隐藏事物。 I would set their actual display style property to 'none' to hide them. 我会将其实际显示样式属性设置为“ none”以隐藏它们。 this would allow you to check this property before showing the tooltips, because checking the z-index of the element might be a little cumbersome. 这将允许您在显示工具提示之前检查此属性,因为检查元素的z-index可能会有些麻烦。

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

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