changing visibility using javascript

后端 未结 3 1194
时光取名叫无心
时光取名叫无心 2020-12-09 16:43

hi i have web page which uses ajax to retrieving data from another pages and while doing that i want to show a loading gif in the page so i\'ve create a div with my gif on i

相关标签:
3条回答
  • 2020-12-09 17:12

    Use display instead of visibility. display: none for invisible and no setting for visible.

    0 讨论(0)
  • 2020-12-09 17:22
    function loadpage (page_request, containerid)
    {
      var loading = document.getElementById ( "loading" ) ;
    
      // when connecting to server
      if ( page_request.readyState == 1 )
          loading.style.visibility = "visible" ;
    
      // when loaded successfully
      if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
      {
          document.getElementById(containerid).innerHTML=page_request.responseText ;
          loading.style.visibility = "hidden" ;
      }
    }
    
    0 讨论(0)
  • 2020-12-09 17:34

    If you just want to display it when you get a response add this to your loadpage()

    function loadpage(page_request, containerid){
       if (page_request.readyState == 4 && page_request.status==200) { 
          var container = document.getElementById(containerid);
          container.innerHTML=page_request.responseText;
          container.style.visibility = 'visible';
          // or 
          container.style.display = 'block';
    }
    

    but this depend entirely on how you hid the div in the first place

    0 讨论(0)
提交回复
热议问题