简体   繁体   English

CTRL + F移动溢出:隐藏<div>

[英]CTRL+F moves overflow:hidden <div>

I am trying to create a slider but discovered that if a user were to use CTRL + F , the position and the <div> element's offset changed and so the slider no longer works the way is should. 我试图创建一个滑块,但发现如果用户使用CTRL + F ,位置和<div>元素的偏移量发生了变化,因此滑块不再适用。

HTML: HTML:

<div style="width:100px; height:150px;">
    <div style="width:100px; height:100px; overflow:hidden;">
        <div id="slider" style="width:200px; height:100px; right:0; position:relative;">
            <div style="width:100px; height:100px; float:left;">visible</div>
            <div style="width:100px; height:100px; float:left;">hidden</div>
        </div>
    </div>
    <input id="sliderbuttonprev" type="button" style="float:left;" value="Prev">
    <input id="sliderbuttonnext" type="button" style="float:right;" value="Next">
</div>

JavaScript (jQuery): JavaScript (jQuery):

$(document).ready(function() { 
    $("#sliderbuttonnext").click(function(){
        $("#slider").animate({right:"+=100px"});
    });
    $("#sliderbuttonprev").click(function(){
        $("#slider").animate({right:"-=100px"});
    });
});

Is there a way to stop CTRL + F finding the hidden sections? 有没有办法阻止CTRL + F找到隐藏的部分?

jsFiddle Demo jsFiddle演示

You cannot prevent browsers from finding hidden content, but you could potentially disable it for the slides. 您无法阻止浏览器查找隐藏的内容,但您可能会为幻灯片禁用它。

For example, if you specify the content within CSS, the browser won't move the content. 例如,如果您在CSS中指定内容,则浏览器不会移动内容。 For example, see here > Is it possible to disable Ctrl + F of find in page? 例如,请参阅此处> 是否可以禁用页面中的查找的Ctrl + F?

<div class="word-foobar"></div>

.word-foobar:before {
    content: "Foobar";
}

As nickf has suggested, you could easily write some JavaScript code to convert actual text to this method. 正如nickf建议的那样,您可以轻松编写一些JavaScript代码来将实际文本转换为此方法。

http://jsfiddle.net/TaZL2/2/ http://jsfiddle.net/TaZL2/2/

If you change your animation to marginLeft instead of the right property, the content doesn't seem to scroll when searching. 如果将动画更改为marginLeft而不是right属性,则搜索时内容似乎不会滚动。 (Chrome/Mac OSX) (Chrome / Mac OSX)

However, a user would still see there was a match and be stumped as to where it could be. 但是,用户仍然会看到匹配并且难以确定它可能在哪里。

 $("#sliderbuttonnext").click(function () {
     $("#slider").animate({
         marginLeft: "-=100px"
     });
 });
 $("#sliderbuttonprev").click(function () {
     $("#slider").animate({
         marginLeft: "+=100px"
     });
 });

i came up with a solution that uses a variable to track the position of the main wrapping div and hides ".hide()" the content div that's not visible. 我想出了一个解决方案,它使用一个变量来跟踪主包装div的位置,并隐藏“.hide()”不可见的内容div。 hidden content is not visible to ctrl f. 隐藏内容对ctrl f不可见。

HTML: HTML:

<div style="width:100px; height:150px;">
<div style="width:100px; height:100px; overflow:hidden;">
    <div id="slider" style="width:200px; height:100px; right:0; position:relative;">
        <div style="width:100px; height:100px; float:left;">
            <div id="id1">visible</div>
        </div>
        <div style="width:100px; height:100px; float:left;">
            <div id="id2">hidden</div>
        </div>
    </div>
</div>
<input id="sliderbuttonprev" type="button" style="float:left;" value="Prev">
<input id="sliderbuttonnext" type="button" style="float:right;" value="Next">

JQuery JQuery的

<script>
var pos = 0;
function showfunct(x){
   if(x==0)$("#id1").show();
   if(x==100)$("#id2").show();
}

function hidefunct(x){
   if(!(x==0))$("#id1").hide();
   if(!(x==100))$("#id2").hide();
}
showfunct(pos);
hidefunct(pos);
$(document).ready(function() { 

$("#sliderbuttonnext").click(function(){
    pos+=100;
    showfunct(pos);
    $("#slider").animate({right:"+=100px"});
    $("#slider").promise().done(function(){
        hidefunct(pos);
    });
});
$("#sliderbuttonprev").click(function(){
    pos-=100;
    showfunct(pos);
    $("#slider").animate({right:"-=100px"});
    $("#slider").promise().done(function(){
        hidefunct(pos);
    });
});
}); 
</script>

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

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