$ ( document ) . ready ( function ( ) {
/ * check in the cookie the resolution of the page to view it * /
if ( $. cookie ( "screen" ) == 'full' ) { / * If the previous viewing was on a wide screen then * /
/ * Add a wide site style class for the main blocks * /
$ ( '#conteiner, # conteiner_2, # conteiner_3, #footer' ) . addClass ( 'tip_full' ) ;
window. sreen_1 = 'fix' ; / * write the initial value for the button changing the width of the page * /
window. sreen_2 = 'full' ; / * secondary value * /
} else { / * in all other cases (including the default) will display a narrow page view * /
/ * Add a style class to a narrow display of the site page for the main blocks * /
$ ( '#conteiner, # conteiner_2, # conteiner_3, #footer' ) . addClass ( 'tip_fix' ) ;
window. sreen_1 = 'full' ; / * primary value * /
window. sreen_2 = 'fix' ; / * secondary value * /
}
/ * The function of changing the width of the screen depending on the parameters passed to it * /
function size_screen ( size_type_1 , size_type_2 ) {
$ ( '#start' ) . css ( 'display' , 'none' ) ; / * Protection against "fool", repeatedly pressing the button // remove the button * /
/ * Assign values ​​to variables depending on the passed parameter (screen width) * /
if ( size_type_1 == 'full' ) {
window. size_width = '100%' ; / * page width * /
} else {
window. size_width = '800px' ;
}
/ * Jquery animation function. In this case, smoothly changing the width of the image of the site page *
$ ( '#conteiner, # conteiner_2, # conteiner_3, # footer' ) . animate ( {
'width' : window. size_width / * Smoothly change the width in accordance with the page display parameter * /
} ,
500 , / * Animation time * /
function ( ) { / * Function called when animation ends * /
/ * Remove previous page display styles from blocks * /
$ ( this ) . removeClass ( 'tip_' + size_type_2 ) ;
/ * Adding a new style class for a new screen width * /
$ ( this ) . addClass ( 'tip_' + size_type_1 ) ;
/ * To clear the html code from garbage, remove the style attribute (created by jquery) * /
/ * This action is not necessary, it has an aesthetic function * /
$ ( this ) . removeAttr ( 'style' ) ;
/ * Protection against "fool": repeatedly pressing the button // showing the button * /
$ ( '#start' ) . css ( 'display' , 'block' ) ;
} ) ;
/ * Write the cookie to display the site after reloading or changing the page * /
$. cookie ( "screen" , size_type_1 , { path : '/' } ) ;
}
$ ( '#start' ) . toggle ( / * The troggle function performs a sequential repeated pressing of an element (button) * /
function ( ) { size_screen ( window. sreen_1 , window. sreen_2 ) ; } , / * first press * /
function ( ) { size_screen ( window. sreen_2 , window. sreen_1 ) ; } / * second press * /
) ;
} )
Source: https://habr.com/ru/post/105171/
All Articles