Forums

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

Home Forums JavaScript Scale text stretch dont work

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240751
    scooterbart
    Participant

    Hello All,

    Im bart, and i got the following problem…

    Im busy for a woocommerce plugin. PHP based but there are some things that must be done in the frontend client side.

    The most of the functions are build in Js

    DEMO URL:
    http://d3.reprex.nl/product/custom/demo-product/

    And HTML output

    <script>
    jQuery(document).ready(function(){
    
    `$img_path = "<?php echo plugins_url( 'woocommerce-custom-design/assets/');?>";
    
    jQuery('span.top-line').html('<img src="'+$img_path+'images/top-line-red.png" />');
    jQuery('div.topText').html(jQuery('#textTop').val()).addClass('redText');
    jQuery('span.bottom').html(jQuery('#textBottom').val()).addClass('redText');
    jQuery('span.bottom-line').html('<img src="'+$img_path+'images/bottom-line-red.png" />');
    `
    
    });
    &lt;/script&gt;
    

    Output client side when keyup():

    &lt;script&gt;
    &lt;div class="logo" style="
    "&gt;&lt;span&gt;&lt;img src="http://d3.reprex.nl/wp-content/plugins/woocommerce-custom-design/assets/images/top-line-red.png" /&gt;&lt;/span&gt;
    
    &lt;div&gt;&lt;div&gt;&lt;span style="letter-spacing: 51.1111px"&gt;urk&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
    
    &lt;span&gt;&lt;img src="http://d3.reprex.nl/wp-content/plugins/woocommerce-custom-design/assets/images/bottom-line-red.png" /&gt;&lt;/span&gt;&lt;/div&gt;
    &lt;/script&gt;
    
    • The problem is that the function right now based on letter-spacing.
    • Is there a way to make a function that calculates like this?

    http://codepen.io/nickwalgers/pen/wGXrXR

    so there is a max-width
    and min-width

    Maybe to early? but verry thanks to take a look at this ish..

    kind regards

    #240752
    scooterbart
    Participant

    Sorry Jquiry

    &lt;script&gt;
    
    jQuery.fn.strech_text = function(){
        var elmt          = jQuery(this),
            cont_width    = elmt.width(),
            txt           = elmt.html(),
            one_line      = jQuery('&lt;span&gt;' + txt + '&lt;/span&gt;'),
            nb_char       = elmt.text().length,
            spacing       = cont_width/nb_char,
    
    `    txt_width;
    
        elmt.html(one_line);
    txt_width = one_line.width();
    
    if (txt_width &lt; cont_width){
        var  char_width     = txt_width/nb_char,
             ltr_spacing    = spacing - char_width + (spacing - char_width)/nb_char ; 
             ltr_transform    = spacing - char_width + (spacing - char_width)-nb_char ; 
            console.log(ltr_spacing);
            console.log(ltr_transform);
        one_line.css({'letter-spacing': ltr_spacing});
        one_line.css({'transform': ltr_transform});
    } else {
        one_line.contents().unwrap();
        elmt.addClass('justify');
    }
    `
    
    };
    
    });
    
    &lt;/script&gt;
    
    
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.