Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Setting variable to animate();

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #45963
    Kuzyo
    Participant

    Hi guys;
    Can I somehow to set variable to css property in animate function, like this

    function showHideTextBlock() {
    var imgWidth = $imgBlock.css(‘width’);
    $textBlock.animate({marginRight: -imgWidth}, 100);
    $textBlock.animate({marginRight: ‘0’}, 300);
    }
    In one code that I saw it work, but my doesn’t work. Looking fo advice. Thanks

    #140964
    pixelgrid
    Participant

    you cant obtain dynamically information about elements in css unless its one elements parent with percentages or inherit or a good use of css calc() function.

    in short no you cant

    #141011
    Kuzyo
    Participant

    @CrocoDillon I understood your main concept:

    > it useful to work in small steps, and test every step you make (using console.log(‘some useful feedback’);)

    It very helpful.

    I checked **console.log(imgWidth);** and it gives me 460px – it what I looking for, but doesn’t work

    #141012
    Kuzyo
    Participant

    I have found this solution

    // hide and show image
    function showHideImgBlock() {
    var imgWidth = $imgBlock.css(‘width’);
    console.log(imgWidth)
    $imgBlock.animate({marginRight: ‘-=’ + imgWidth}, 10);
    $imgBlock.animate({marginRight: ‘0’}, 600);
    }

    showHideImgBlock() ;

    or could I make this more simple?

    #141014
    Kuzyo
    Participant

    oh yes I could :))

    animate({marginRight: ‘-‘ + imgWidth}

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.