使用jQuery在Window height处选择最接近的Div

时间:2014-09-08 21:38:25

标签: jquery html

我有这个:

<div class="blocks">
        <div class="col1">
            <div class="block1"></div>
            <div class="block2"></div>
        </div>
        <div class="col2">
            <div class="block1"></div>
            <div class="block2"></div>
        </div>
        <div class="col3">
            <div class="block1"></div>
            <div class="block2"></div>
        </div>
    </div>  

    <script>
        $(function(){
            var windowHeight = $(window).height();
            var columnHeight = $('.col1').height(); //col class can vary
            var adHeight = (0.65 * windowHeight);
            if(columnHeight > adHeight){
                //get the closest div showing at adHeight height and append iframe src after this div
                $ex = closestDiv('col1'); //function will be called to get closest div
                $ex.after(
                    'adblock'
                );
            }
        });

        function closestDiv(column){
            //block of code ??
            return 'div'; //should either be block1 or block2 class
        }
    </script>

我正在尝试为接近adHeight的col类获取最接近的div。

这样,我可以在该div之后添加一个新的html广告。

这可以通过jquery吗?

0 个答案:

没有答案