Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

html - Call javascript function, when row contains certain amount of columns

I'm working on a MVC application. One of the pages contains a row and two columns.

When you resize the window to a certain width it automatically puts the second column under the first one.

I'm using the bootstrap grid system to achieve this.

        <div class="row">
            <div id="draftContainer" class="col-md-6 col-sm-6 col-lg-6">
                ...
                (Some content)
                ...
            </div>
            <div id="releaseContainer" class="col-md-6 col-sm-6 col-lg-6" >
                ...
                (Some other content)
                ...

            </div>
        </div>

I would like to know if its possible to somehow fire an event when the second column drops under the first and then call a javascript function.

The case is, that I have some CSS classes that should be added and removed depending on whether theres one or two columns.

I hope you get the idea.

Thanks in advance

question from:https://stackoverflow.com/questions/66061469/call-javascript-function-when-row-contains-certain-amount-of-columns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I want to help

https://codepen.io/sinandogan/pen/YzpwvRL

<div class="row">
    <div id="draftContainer" class="col-md-6 col-sm-6 col-lg-6">
        ...
        (Some content)
        <input type="hidden" id="css1" value="<style>#draftContainer{background:#d8ffc0} #releaseContainer{background:#eee}</style>" />
        ...
    </div>
    <div id="releaseContainer" class="col-md-6 col-sm-6 col-lg-6" >
        ...
        (Some other content)
        <input type="hidden" id="css2" value="<style>#draftContainer{background:#eee} #releaseContainer{background:#f44336}</style>" />
        ...

    </div>
</div>
<div id="appendStyle"></div>

<script> 
  function control(){
    if($('body').width() > 766){
        $('#appendStyle').html($('#css1').val());
    }else{
        $('#appendStyle').html($('#css2').val());
    }
  }
  
  //first run
  control();
  
  $(document).ready(function() {
    $(window).resize(function(){
        control();
    });
  });
  </script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...