Place link inside Jquery -
i using code found on jsfiddle http://jsfiddle.net/mekwall/fnyhs/ since seems best situation need dynamical text fit container (by changing font size).
(function($) { $.fn.textfill = function(maxfontsize, maxwords) { maxfontsize = parseint(maxfontsize, 10); maxwords = parseint(maxwords, 10) || 4; return this.each(function(){ var self = $(this), orgtext = self.text(), fontsize = parseint(self.css("fontsize"), 10), lineheight = parseint(self.css("lineheight"), 10), maxheight = self.height(), maxwidth = self.width(), words = self.text().split(" "); function calcsize(text) { var ourtext = $("<span class='dyntextval'><a href='#' class='trigger'>"+text+"</a></span>").appendto(self), multiplier = maxwidth/ourtext.width(), newsize = fontsize*(multiplier-0.1); ourtext.css( "fontsize", (maxfontsize > 0 && newsize > maxfontsize) ? maxfontsize : newsize ); var scrollheight = self[0].scrollheight; if (scrollheight > maxheight) { multiplier = maxheight/scrollheight; newsize = (newsize*multiplier); ourtext.css( "fontsize", (maxfontsize > 0 && newsize > maxfontsize) ? maxfontsize : newsize ); } } self.empty(); if (words.length > maxwords) { while (words.length > 0) { var newtext = words.splice(0, maxwords).join(" "); console.log calcsize(newtext); self.append("<br>"); } } else { calcsize(orgtext); } }); }; })(jquery); $(document).ready(function() { $('.large').textfill({ maxfontpixels: 120, minfontpixels: 36}); $('.medium').textfill({ maxfontpixels: 32 }); $('.small').textfill({ maxfontpixels: 18 }); }); but having problem part:
var ourtext = $(""+text+"").appendto(self), the thing need link inside there toggles div once clicked.
the toggle:
$(".side-toggle").hide(); $('.trigger').click(function() { $(this).closest('.group').find('.side-toggle').slidetoggle(); return false; //prevent browser jump link anchor }); $(".toggle").click(function() { $(this).next(".group").slidetoggle(); }); the toggle works itself, not when implement code text fill code.
the html:
<div class="quepasa"> <div class="large artist"> <span class="dyntextval"> <a title="<?php the_title();?>" href="#" class="trigger"> <?php if ( get_the_title() ) the_title(); else the_id(); ?>+ </a> </span> </div> </div> i don't have enough jquery knowledge know how: a) put link in? b) keep toggle function
i hope out there can me out.
what's happening toggle break in javascript stack, or simply, error on makes else go hell.
example:
let's causes error (cannot call bar on undefined)
var darth = $('#foo').data().bar;
then in block of code:
$('#threepeeoh').hide(); var darth = $('#foo').data().bar; $('luke').show('fade', 500); #luke never show because there error on line before. #threepeeoh able hide because did before darth showed , threw error. , code happens after not executed. (it's worth googling " js try/catch blocks")
so, when add textfill code, must throwing error , making seem toggle fubar.
as far error is, need learn use javascript debugger web browser , see error thrown. far can tell, var ourtext = $(""+text+"").appendto(self) isn't in code block posted, nor fiddle, don't know you're talking about.
so:
- go find developer console use javascript debugger (firefug popular, chrome has 1 built in, hit ctrl shift j)
- refresh, error (most in red)
- edit question (might better ask new one) , post error code near error thrown ( file , line number provided )
- if possible, upload sample of work public server don't plan delete, community can reference it.
Comments
Post a Comment