Tag Archives: jQuery

jQuery Toggle/Manipulate FontAwesome 5

FontAwesome is great, but after upgrade to 5, there are prefix types (far, fas, fab) added and then the way to render with SVG/JS to make its mess.  There are 2 types of use, but SVG/JS is way better in advance features to decorate the icons.

Not sure if it’s only me that seems the manual/instruction on how to manipulate the font awesome using SVG/JS does not work as promise. I have to figure it out myself.

So here is my solutions

This is jQuery toggle function to change from <i class=”fas fa-plus-circle”></i> to <i class=”fas fa-minus-circle”></i> icon

jQuery('.btn').on("click", function(){
   jQuery(this).find('[data-fa-i2svg]')
       .attr('data-prefix', 'fas');
    if (jQuery(this).find('[data-fa-i2svg]')
       .attr('data-icon') == 'minus-circle') {
         jQuery(this).find('[data-fa-i2svg]')
           .removeClass('fa-minus-circle')
           .addClass('fa-plus-circle')
           .attr('data-icon', 'plus-circle');
   }else{
         jQuery(this).find('[data-fa-i2svg]')
           .removeClass('fa-plus-circle')
           .addClass('fa-minus-circle')
           .attr('data-icon', 'minus-circle');
   }
});

Explanation:

  1. There are 2 elements that shared ‘data-fa-i2svg’ attribute (<i> and <svg>)
  2. You have to find the element with attribute ‘data-fa-i2svg’ then  add/remove class with original FontAwesome class which starts with fa-xxxxx.
  3. Change the attribute ‘data-icon’ to the FontAwesome class (eliminate the fa- prefix)
  4. Last thing, change the attribute ‘data-prefix'  to make it correct prefix type for each icon.

 

jStarbox Does Not Show Stars on Hidden Tab

If you are using jStarbox so you know what I refer to.

I have downloaded Flat Bootstrap Responsive Website to tried jStarbox and was on the UI implementation. It was so messy because I have it on my hidden tab. After switch the tab to appear the rating stars not display as expected. I spent about 2 days for this as I am not that good with jQuery and Javascript much.

jStarbox

The visible tab is fine, but the hidden tabs seems has problem. I am not sure because of the design or the jStarbox does not have this prevention.

It appeared that .colorbar not set to the size of .positioner after visible. (.positioner still have width of 0px) here is what I do.

starbox.starbox(‘setOption’, ‘average’, averageVal); //call method to reset the average value

var size = 85; //manual fixed the size

positioner.children(‘.stars’).children(‘.colorbar’).css(“width”, (averageVal*size)+”px”); //add style

To try jStarBox Click here https://github.com/sabberworm/jStarbox

Project: Custom Shopping Cart

activo-technology_1239580669254
This one is an anonymous project so I can’t tell who is the owner and what is the project about. The project made in PHP & MySQL. I got this project through ThaiFreelanceBid. It’s kind of urgent work that has to be done on April 12th… Oh shit now it is April 13th and I still lag for the work. LOL

Anyway, this project use jQuery, Custom Shopping Cart with PHP & MySQL. Non template framework as I have to continue this work from someone else. Budget $514 for 26 days. (Thai customer)