BullGuard Antivirus Sale - 60% Off with openElement !
Forum Home Forum Home >

openElement

> openElement General Discussion
  New Posts New Posts RSS Feed - Icon change after mouse click
  FAQ FAQ  Forum Search   Register Register  Login Login

Icon change after mouse click

 Post Reply Post Reply
Author
Message
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: Aug 02 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Topic: Icon change after mouse click
    Posted: Jan 17 2017 at 2:43pm
Hi! OE Team,

I am implementing the feature that (for example):
    1. User click a lock icon (current status is unlock.)
    2. all text box are changed to "Read-only"
    3. After that a lock icon is changed to "unlock icon" automatically.
Unlock process is just toggle.

OpenElement has a feature when mouse is hovering on icon, icon is changed to other picture.
But I have difficulty that how I can change the icon after clicking.

Do you have any idea to implement this feature?

Thank you so much!

DJ
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group


Joined: May 31 2012
Status: Offline
Points: 5283
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: Jan 17 2017 at 5:12pm
Hi,

It's better to code this manually.

Add a Custom Class "button-lock" to your element (whatever it is - just not the Image Link with images already specified, to avoid conflicts, and not the Image either).
Add a Custom Class "cb-lock" to all checkboxes to affect,

Add a Code Block Source type CSS:

.button-lock {
  background: center center no-repeat;
  background-size: contain;
}

.button-lock, .button-lock.locked:hover {
  background-image: url(Files/Other/my-images/unlocked.jpg);
}
.button-lock.locked, .button-lock:not(.locked):hover {
  background-image: url(Files/Other/my-images/locked.jpg);
}

Of course add corresponding images to Files/Other (to make sure they upload automatically) and modify URLs as needed.

Then add a Code Block Source type Javascript:


$(function(){
  $('.button-lock').click(function(){
    var isLocked = $(this).hasClass('locked');
    $(this).toggleClass('locked');
    $('.cb-lock  input').prop('checked', isLocked);  }); // here check whether it works in the good direction, otherwise put ! in front of isLocked: prop('checked', !isLocked)
});


Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: Aug 02 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: Jan 24 2017 at 4:42pm
Thanks DmitOE, I learned the usage of .hasClass() & .toggleClass() from your code.
I put !isLocked instead of ('readonly', isLocked);
Because, at first to toggle the class, it works when click twice.

I am coding the icon changing now...but it looks not easy...


Edited by djju1029 - Jan 24 2017 at 5:09pm
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.