Jquery 计算视口中div的宽度

Jquery 计算视口中div的宽度,jquery,html,width,Jquery,Html,Width,我需要计算视口中div的宽度。如果我在div上使用.css(width),它只计算完整的宽度 我当前尝试计算的代码: var $Windowwidth = $(window).width(); var $lefty = $("#gallerytop"); var $GalleryTopWidth = parseInt($lefty.css('width')); $("#footer").click(function() { alert($Windowwidth) alert($G

我需要计算视口中div的宽度。如果我在div上使用.css(width),它只计算完整的宽度

我当前尝试计算的代码:

var $Windowwidth = $(window).width();
var $lefty = $("#gallerytop");
var $GalleryTopWidth = parseInt($lefty.css('width'));
$("#footer").click(function() {
    alert($Windowwidth)
    alert($GalleryTopWidth)
});
我希望实现以下目标:

我有一个div覆盖了我的整个窗口宽度(100%及以上)。我有两个按钮,用于按241px左右设置该div的动画。如果我的移动div已经到达我的视口中的某个点(例如,通过右键点击DIV的右端,现在在我的视窗/窗口中,现在我不想再点击右键了),我就能够设置一个停止。 有人能帮忙吗


谢谢大家!

我可能会使用div的左位置(
$(..).offset().left
)来控制它是否到达视口中的该点。我可能会使用div的左位置(
$(..).offset().left
)来控制它是否到达视口中的该点。

var$aantal=$(“#gallerytop img”).size()$(“#厨房顶部img:first”).width();
var $aantal = $("#gallerytop img").size() * $("#gallerytop img:first").width();
var $viewportsize = parseInt($(window).width() / $("#gallerytop img:first").width());
var $overflow = $("#gallerytop img").size() - $viewportsize;
var $clickcount = 0;
var $extrabijtellen = 0;
var $isScrolling = false;
var $extrabijtellendynamisch = $(window).width()/10;

$("#next").click(function() {
    var $lefty = $("#gallerytop, #gallerybottom");
    if ($clickcount < $overflow && !$isScrolling) {
        $isScrolling = true;
        if ($clickcount == ($overflow - 1)) {
            $extrabijtellen = $extrabijtellendynamisch;
        }
        else {
            $extrabijtellen = 0;
        }
        $lefty.stop().animate({
            left: (parseInt($lefty.css('left'), 10) - ($("#gallerytop img:first").width() + $extrabijtellen))
        }, "normal", function() { $isScrolling = false; });
        $clickcount++;
    }
});

$('#prev').click(function() {
    var $righty = $("#gallerytop, #gallerybottom");
    if ($clickcount > 0 && !$isScrolling) {
        $isScrolling = true;
        if ($clickcount == ($overflow - 1)) {
            $extrabijtellen = $extrabijtellendynamisch;
        }
        else {
            $extrabijtellen = 0;
        }
        $righty.stop().animate({
            marginLeft: (parseInt($righty.css('marginLeft'), 10) + ($("#gallerytop img:first").width() + $extrabijtellen))
        }, "normal", function() { $isScrolling = false; });
        $clickcount--;
    }
});

if (($aantal) > $viewportsize) {
    $("#prev, #next").css("display", "block");
}
var$viewportsize=parseInt($(窗口).width()/$(“#gallerytop img:first”).width()); var$overflow=$(“#gallerytop img”).size()-$viewportsize; var$clickcount=0; var$extrabijtellen=0; var$IsCrolling=假; var$extrabijtellendynamisch=$(窗口).width()/10; $(“#下一步”)。单击(函数(){ var$lefty=$(“#gallerytop,#gallerybottom”); 如果($clickcount<$overflow&!$IsCrolling){ $isScrolling=true; 如果($clickcount==($overflow-1)){ $extrabijtellen=$extrabijtellendynamisch; } 否则{ $extrabijtellen=0; } $lefty.stop().animate({ 左:(parseInt($lefty.css('left'),10)-($(“#gallerytop img:first”).width()+$extrabijtellen)) },“正常”,函数(){$isScrolling=false;}); $clickcount++; } }); $('#prev')。单击(函数(){ var$righty=$(“#gallerytop,#gallerybottom”); 如果($clickcount>0&!$IsCrolling){ $isScrolling=true; 如果($clickcount==($overflow-1)){ $extrabijtellen=$extrabijtellendynamisch; } 否则{ $extrabijtellen=0; } $righty.stop().animate({ marginLeft:(parseInt($righty.css('marginLeft'),10)+($(“#gallerytop img:first”).width()+$extrabijtellen)) },“正常”,函数(){$isScrolling=false;}); $clickcount--; } }); 如果(($aantal)>$viewportsize){ $(“#上一页,#下一页”).css(“显示”、“块”); }
var$aantal=$(“#gallerytop img”).size()*$(“#gallerytop img:first”).width();
var$viewportsize=parseInt($(窗口).width()/$(“#gallerytop img:first”).width());
var$overflow=$(“#gallerytop img”).size()-$viewportsize;
var$clickcount=0;
var$extrabijtellen=0;
var$IsCrolling=假;
var$extrabijtellendynamisch=$(窗口).width()/10;
$(“#下一步”)。单击(函数(){
var$lefty=$(“#gallerytop,#gallerybottom”);
如果($clickcount<$overflow&!$IsCrolling){
$isScrolling=true;
如果($clickcount==($overflow-1)){
$extrabijtellen=$extrabijtellendynamisch;
}
否则{
$extrabijtellen=0;
}
$lefty.stop().animate({
左:(parseInt($lefty.css('left'),10)-($(“#gallerytop img:first”).width()+$extrabijtellen))
},“正常”,函数(){$isScrolling=false;});
$clickcount++;
}
});
$('#prev')。单击(函数(){
var$righty=$(“#gallerytop,#gallerybottom”);
如果($clickcount>0&!$IsCrolling){
$isScrolling=true;
如果($clickcount==($overflow-1)){
$extrabijtellen=$extrabijtellendynamisch;
}
否则{
$extrabijtellen=0;
}
$righty.stop().animate({
marginLeft:(parseInt($righty.css('marginLeft'),10)+($(“#gallerytop img:first”).width()+$extrabijtellen))
},“正常”,函数(){$isScrolling=false;});
$clickcount--;
}
});
如果(($aantal)>$viewportsize){
$(“#上一页,#下一页”).css(“显示”、“块”);
}

这对我的情况没有帮助,因为移动div的宽度是可变的(动态构建)…我真的不明白,图层可以有任何宽度,它的左侧位置将是相同的,不是吗?是的,这有点难以解释。无论如何,我自己发现了它。非常复杂!我在下面发布了答案。无论如何,谢谢!这对我的情况没有帮助,因为移动div的宽度是可变的(动态构建)…我真的不明白,这个图层可以有任何宽度,它的左边位置会是一样的,不是吗?是的,这有点难以解释。总之,我自己发现的。相当复杂!我在下面发布了答案。无论如何,谢谢!