Alfred Kwak
Alfred Kwak

Reputation: 85

Loading a .txt instead of an image file into jquery

How I can load a .txt file instead of an image. I'm using a rotate on scroll. So each time you scroll a new image flips up. I'd like to change this image to just plain text.

CSS:

#tourniquetpers{
position: fixed;    
width: 25%;
top:0px;
left:75%;
bottom:0px;
-webkit-perspective: 600px; /* Chrome, Safari, Opera */
perspective: 600px;
z-index: 999998;
display: block;

}

#tourniquet{
position: fixed;    
width: 100%;
top:0px;
left:0px;
bottom: 0px;
background-color: black;
z-index: 999999;
background: red;
background-image:url();
background-repeat: no-repeat;
background-attachment: absolute;
background-position: center;  
background-size: 50%;
overflow: hidden;

jQuery :

var ScrollTop = $(window).scrollTop()
    /*img01*/
    if ( ScrollTop > 0 && ScrollTop <  (bodyHeight/2)){

    /*console.log('image02')*/
    $("#tourniquetpers").css('display','block')
    /*$("#tourniquet").find('img').attr('src', "pages/04.png");*/
    $('#tourniquet').css("background-image", "url(athena_01.png)");  

    };

    /*img02*/
    if ( ScrollTop > (bodyHeight/2) && ScrollTop < (bodyHeight + (bodyHeight/2) )) {

    /*console.log('image02')*/
    $("#tourniquetpers").css('display','block')

    /*$("#tourniquet").find('img').attr('src', "pages/02.jpg");*/
    $('#tourniquet').css("background-image", "url(athena_02.png)");  

    };

I tried to change it to load a .txt file but the div stays empty. Thanks in advance

Upvotes: 0

Views: 93

Answers (1)

Miguel
Miguel

Reputation: 20633

https://api.jquery.com/load/

$('#tourniquet').load('file.txt', function(response, status, xhr) {
  if (status === 'error') {
    console.error(xhr.statusText);
  }
});

Upvotes: 1

Related Questions