risq / jquery-advanced-news-ticker

(deprecated) - A powerful, flexible and animated vertical news ticker plugin for JQuery.
http://risq.github.io/jquery-advanced-news-ticker
GNU General Public License v2.0
297 stars 104 forks source link

row_height setting for responsive design #10

Closed desmond86 closed 10 years ago

desmond86 commented 10 years ago

Hi there, I am using the example 'nt_example1' to create a news ticker. Is it possible to customize row_height dynamically according to the screen resolution? For example, if the screen resolution 1024px, the row_height is set to be 100px. However, if the screen resolution is smaller than that, I would need around 150px for the row_height. Is there any way to change it based on the screen resolution?

Or is it possible to adjust the row_height according to the size of the content?

risq commented 10 years ago

Hi, The plugin does not currently support fluid row height. However, you can achieve this very easily using updateOption method. Check this fiddle : http://jsfiddle.net/h7kxC/ (try to resize the viewport)

I just created a function which check the current window width and update the plugin's row_height :

function checkWidth() {
    if($(window).width() < 680){
        nt.newsTicker('updateOption','row_height','24');
        $('.newsticker').height(48);
    }
    else {
        nt.newsTicker('updateOption','row_height','48');
        $('.newsticker').height(92);
    }
};

This function is called on document ready. Additionally, don't forget to call it on resize event :

$(window).resize(checkWidth);  
klentoy commented 10 years ago

or use the "hasMoved" option like this for dynamic height: hasMoved: function(){ var visibleHeight = $('.newsticker li:visible').height(); visibleHeight = visibleHeight - 1; $('.newsticker').animate({'height': visibleHeight}, 100); } and also add this to the resize function