Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果#foo+;左偏移大于页面宽度_Javascript_Jquery_Debugging_Syntax - Fatal编程技术网

Javascript 如果#foo+;左偏移大于页面宽度

Javascript 如果#foo+;左偏移大于页面宽度,javascript,jquery,debugging,syntax,Javascript,Jquery,Debugging,Syntax,好的,我尝试使用jQuery获取元素的预览的innerWidth()。我想创建一个条件,说明如果x offset LEFT+#preview width大于页面宽度,则为其指定样式right:z,其中z=#preview width+xOffset 很抱歉,我下面的代码乱七八糟,而且.css(“right”,(rightFloat+xOffset)+“px”)(第125行)的语法不正确,但这是我的问题的一部分 <script> $(document).ready(funct

好的,我尝试使用jQuery获取元素的
预览
innerWidth()。我想创建一个条件,说明如果x offset LEFT+#preview width大于页面宽度,则为其指定样式
right:z
,其中z=#preview width+xOffset

很抱歉,我下面的代码乱七八糟,而且
.css(“right”,(rightFloat+xOffset)+“px”)
(第125行)的语法不正确,但这是我的问题的一部分

<script>

    $(document).ready(function(){

    //append "gallery" class to all items with "popup" class
    imagePreview();
    $(".popup").addClass("gallery");
});    

//The overlay or pop-up effect
this.imagePreview = function() { /* CONFIG */

    xOffset = 40;
    yOffset = 40;

    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
    /* END CONFIG */
    $("a.preview").click(function(e) {
        return false;
    });
    $("a.preview").hover(function(e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        var rightFloat = e.pageX + ("#preview").innerWidth;
        $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
        $("#preview").hide().css("top", (e.pageY - yOffset) + "px").css("left", (e.pageX + xOffset) + "px").fadeIn("2000");
        while ((left + 400) > window.innerWidth) {.css("right", (rightFloat + xOffset) + "px")
        }
    }, function() {
        this.title = this.t;
        $("#preview").remove();
    });
    $("a.preview").mousemove(function(e) {
        var top = e.pageY - yOffset;
        var left = e.pageX + xOffset;
        var rightFloat = e.pageX + ("#preview").innerWidth;
        //flips the image if it gets too close to the right side
        while ((left + 400) > window.innerWidth) {.css("right", +(rightFlaot + xOffset) + "px")
        }
        $("#preview").css("top", top + "px").css("left", left + "px");
    });
};


</script>

$(文档).ready(函数(){
//将“gallery”类附加到具有“popup”类的所有项目
图像预览();
$(“.popup”).addClass(“gallery”);
});    
//覆盖或弹出效果
this.imagePreview=函数(){/*配置*/
xOffset=40;
yOffset=40;
//这两个变量确定弹出窗口与光标的距离
//您可能需要调整以获得正确的结果
/*结束配置*/
$(“a.preview”)。单击(函数(e){
返回false;
});
$(“a.preview”).hover(函数(e){
this.t=this.title;
this.title=“”;
var c=(this.t!=”)?“
”+this.t:”; var rightFloat=e.pageX+(“#预览”).innerWidth; $(“正文”)。追加(“

”+c+”

”; $(“#预览”).hide().css(“顶部”(e.pageY-yOffset)+“px”).css(“左侧”(e.pageX+xOffset)+“px”).fadeIn(“2000”); while((left+400)>window.innerWidth){.css(“right”,(rightFloat+xOffset)+“px”) } },函数(){ this.title=this.t; $(“#预览”).remove(); }); $(“a.preview”).mousemove(函数(e){ var top=e.pageY-yOffset; var left=e.pageX+xOffset; var rightFloat=e.pageX+(“#预览”).innerWidth; //如果图像太靠近右侧,则翻转图像 while((left+400)>window.innerWidth){.css(“right”、+(rightFlaot+xOffset)+“px”) } $(“#预览”).css(“顶部”,顶部+“px”).css(“左侧”,左侧+“px”); }); };
尝试使用

if($('#preview').offset()。右尝试使用


if($('#预览').offset().right基本上我搞砸了语法,我想我很接近,但它现在失败是因为语法错误。基本上我搞砸了语法,我想我接近,但它现在失败是因为语法错误。谢谢。不幸的是,你在这里创建的
rightFloat
值对函数没有任何影响。这个想法是t而不是
位置:left
它测试#preview+
$(“preview”)的xPosition。innerwidth()
…如果total>大于窗口的总宽度,(例如,照片会在页面边距之外被剪掉,然后它会将其改为
右侧:y
其中y=#preview.innerWidth+xOffset。您可以在开发网站上看到它基本正常工作:。如果将照片悬停(向下滚动页面),则会显示错误。)在最左边-它们出现在屏幕外。啊,这更有意义。我的第一个答案可能没有多大帮助。在上面进行了修改。谢谢。不幸的是,您在这里创建的
rightFloat
值对函数没有任何影响。其思想是,它不是
position:left
而是测试#预览的xPosition+
$(“预览”).innerwidth()
…如果总>大于窗口的总宽度,(例如,照片会在页面边距之外被剪掉,然后它会将其改为
右侧:y
其中y=#preview.innerWidth+xOffset。您可以在开发网站上看到它基本正常工作:。如果将照片悬停(向下滚动页面),则会显示错误。)在最左边-它们出现在屏幕外。啊,这更有意义。我的第一个答案可能没有多大帮助。修订如上。
if($('#preview').offset().right<0){
   var right = parseInt($(window).width()) - e.pageX + xOffset;
   $("#preview").css("top", top + "px").css("right", right + "px");
}else{
   var left = e.pageX + xOffset;
   $("#preview").css("top", top + "px").css("left", left + "px");
}