0

Echo a PHP string value(s) as caption on hover?

Website structure:

  • 1x landing-page (index, selection work)
  • 1x Work-page (overview all work)
  • ?x Project-page(s)

I have navigation build where project-title is part of the header/navigation. String values on the project-page are echoed for the nav-info ($title + $category) when on a project-page.

The primary navigation nav-primary(Work + Information) will be replaced by the nav-info and could be reached again by hovering the header. That all works fine, but i was wondering if it is possible to do the same thing for showing the caption as echo string on hover.

Landing-page and work-page have thumbnails with hover actions for showing the captions. My thinking was if i use echo string as figcaption than when hovering it will show up as nav-info and return to nav-primary when not hovering, my idea was building it like this:

<div class="grid-12-span">
    <a href="/work/project-x">
        <img
        src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1.414'%3E%3C/svg%3E"
        data-src="/images/project-x-01.jpg" 
        class="lazyload"
        alt="">
        <figcaption><?php $title = "Project X"; $category = "Spatial"; ?></figcaption>
    </a>
</div>

Header/navigation:

<header>
    <nav>
    <ul class="nav-primary">
        <li><a href="/work">Work</a></li>
        <li><a href="/information">Information</a></li>
    </ul>
    <ul class="nav-info">
        <li class="title"><?php echo $title; ?></li>
        <li class="category"><?php echo $category; ?></li>
    </ul>
    </nav>
</header>

CSS:

a:hover figcaption {
    opacity: 1;
    -webkit-transition: opacity 0.2s;
    transition: opacity 0.2s;
}

figcaption {
    opacity: 0;
    font-size: inherit;
    position: relative;
    float: left;
    top: 0;
    left: 0;
    text-align: left;
    padding: 3px 0 0;
    width: 100%;
}
Minding
  • 1,383
  • 1
  • 17
  • 29
KP83
  • 616
  • 1
  • 10
  • 34
  • You cannot perform a PHP function on the client-side. – Jay Blanchard Jan 02 '20 at 15:12
  • Yes, but will try it again now, first time no succes with it...maybe done something wrong not syre – KP83 Jan 02 '20 at 15:13
  • So when it adds the header part and the footer part with include php it doesn't work after that by using php echo string into the caption part in client-side. – KP83 Jan 02 '20 at 15:20

0 Answers0