Created
December 29, 2017 07:44
-
-
Save carolina-vallejo/334a88acc1f8f1d2dcaa36db8e3fe4e8 to your computer and use it in GitHub Desktop.
#javacsript insert floating frame with text in a body with multiple paragraphs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertflotantes() { | |
//--traer el num act de la noticia | |
var elparent = $('#noticias-content-wrapper'); | |
//---comprobar si hay flotantes | |
var numflotants = elparent.find('.flotante').length; | |
if (numflotants > 0) { | |
//---traer el contenido | |
var elcontent = elparent.find('.contenido > .inner-row > *'); | |
//---filtrar el contenido por los parrafos con más de 100 palabras | |
var ponlytext = elcontent.filter(function() { | |
return $.trim($(this).text()).length > 100; | |
}); | |
//--cuantos parrafos hay? | |
var numparrs = ponlytext.length; | |
//--calcular cada cuantos parrafos insertar flotante | |
var eachp = parseInt((numparrs / numflotants) / 3); | |
//----insertar flotantes en el texto | |
for (var i = 0; i < numflotants; i++) { | |
var place = parseInt(eachp + ((numparrs / numflotants) * i)); | |
$(ponlytext[place]).prepend('<div class="flotantes insertion"></div>'); | |
$(ponlytext[place]).children('.insertion').prepend(elparent.find('.flotante')); | |
} | |
} //----if | |
} //--insertflotantes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment